package com.eling.elcms.travel.service.impl;

import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.core.util.PropertyUtils;
import com.eling.elcms.travel.dao.IDestinationDao;
import com.eling.elcms.travel.model.Destination;
import com.eling.elcms.travel.model.PlanItem;
import com.eling.elcms.travel.service.IDestinationManager;
import com.eling.elcms.travel.service.IPlanItemManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class DestinationManagerImpl extends GenericManagerImpl<Destination, Long> implements IDestinationManager{
	
	IDestinationDao destinationDao;
	
	@Autowired
	private IPlanItemManager planItemManager;
	
	@Autowired
	public void setDao(IDestinationDao dao) {
        this.dao = dao;
        this.destinationDao = dao;
    }

	@Override
	public List<Destination> queryChargeDes(Destination cond) {
		List<PlanItem> planItemList = planItemManager.getAll();
		List<Destination> returnList = new ArrayList<Destination>();
		if(!planItemList.isEmpty()){
			List<Destination> desList = planItemList.stream().map(a->a.getDestination()).collect(Collectors.toList());
			List<Long> pkList = desList.stream().map(b->b.getPkDestination()).collect(Collectors.toList());
			PropertyUtils.setProperty(cond, "pkDestinationIn", pkList);
			returnList = destinationDao.query(cond);
		}
		return returnList;
	}

}
